/*
 *   Copyright (C) 2009  Jens Kieselbach
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */
package de.kieselbach.grootional.component

import de.kieselbach.swing.*
import javax.swing.*

import java.awt.BorderLayout

abstract class Card extends JPanel {

    def title
    def icon
    def toolBarItems = []
    def addToolBarGlue = true

    def closeButton
    def closeButtonState
    def closeIcon
    def closeModifiedIcon
    boolean modified = false

    def processableButton
    boolean processing = false
    boolean processable = false

    Card() {
        super()
    }

    Card(def layout) {
        super(layout)
    }

    void setModified(boolean m) {
        if(m != modified) {
            modified = m
            closeButton.icon = modified ? closeModifiedIcon : closeIcon
        }
    }

    boolean isModified() {
        modified
    }

    void startProcessing() {

        if(!processing) {
            processing = true

            if(closeButton != null) {
                closeButtonState = closeButton.enabled
                if(closeButtonState) {
                    closeButton.enabled = false
                }
            }

            if(processableButton != null) {
                processableButton.start()
            }
        }
    }


    void stopProcessing() {

        if(processing) {
            processing = false

            if(closeButton != null) {
                if(closeButtonState) {
                    closeButton.enabled = true
                }
            }

            if(processableButton != null) {
                processableButton.stop()
            }
        }
    }

    void dispose() {
        // override this method if you need to cleanup things
    }
}
